package com.elasticsearch.jd_study.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ program: jd_study
 * @ description:
 * @ author: Mr.Zhongsf
 * @ create: 2021-02-26 16:14
 **/

//集成到springBoot的两步骤
//1.找到对象
//2.注入 放到spring中待用
//3.分析源码

//springBoot 源码中只有两个操作
//1.自动配置: XXXXAutoConfiguration
//2.配置类: XXXXProperties

@Configuration  //相当于xml配置文件 配置bean
public class ElasticSearchConfig {

    @Bean
    public RestHighLevelClient restHighLevelClient(){

        //使用es highClient 绑定本地客户端 使用build构建器构建对象client 方便使用的时候拿出来用
        //相当于spring <beans id = "restHighLevelClient" class = "RestHighLevelClient">
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(
                        new HttpHost("127.0.0.1",9200,"http")
                )
        );

        return client;
    }

}
